package top.v5it.japi.plus.common.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 存储auth上下文信息
 *
 * @author zhanpu
 * @date 2021/4/26
 */
public final class AuthorizedContextHolder {

    /**
     * 存储认证成功后全局授信信息，本地线程安全
     */
    private static final ThreadLocal<Authorized> REQUEST_AUTH_ATTRIBUTES_HOLDER = new TransmittableThreadLocal<>(Boolean.TRUE);

    /**
     * 删除
     */
    public static void resetRequestAuthAttributes() {
        REQUEST_AUTH_ATTRIBUTES_HOLDER.remove();
    }

    /**
     * 设置
     *
     * @param authorized {@link Authorized}
     */
    public static void setRequestAuthAttributes(Authorized authorized) {
        REQUEST_AUTH_ATTRIBUTES_HOLDER.set(authorized);
    }

    /**
     * 获取
     *
     * @return {@link Authorized}
     */
    public static Authorized getRequestAuthAttributes() {
        return REQUEST_AUTH_ATTRIBUTES_HOLDER.get();
    }
}
